
package com.sne.airways.system.dao.impl;

import com.sne.airways.basecore.dao.impl.BaseDAOHibernate;
import com.sne.airways.system.dao.OperationLogDAO;
import com.sne.airways.system.pojo.TdOperationLog;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: 卞京帅{bjslogin@gmail.com}
 * Date: 12-11-25
 * Time: 上午11:02
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class OperationLogDAOHibernate extends BaseDAOHibernate implements OperationLogDAO{

    public List<TdOperationLog> queryOperationLogList(int start, int limit,String moduleName,String opTypeName) {
        Session session = getSession();
        StringBuffer sb = new StringBuffer();
        sb.append(" from TdOperationLog ol where 1=1 ");
        if (StringUtils.isNotBlank(moduleName)){
            sb.append(" and ol.moduleName like :moduleName ");
        }
        if (StringUtils.isNotBlank(opTypeName)){
            sb.append(" and ol.opTypeName like :opTypeName ");
        }
        Query query=session.createQuery(sb.toString());
        if (StringUtils.isNotBlank(moduleName)){
            query.setString("moduleName", "%"+moduleName+"%");
        }
        if (StringUtils.isNotBlank(opTypeName)){
            query.setString("opTypeName","%"+opTypeName+"%" );
        }
        return   query.setFirstResult(start).setMaxResults(limit).list(); //To change body of implemented methods use File | Settings | File Templates.
    }
    public Integer queryOperationLogCount(String moduleName,String opTypeName) {
        Session session = getSession();
        StringBuffer sb = new StringBuffer();
        sb.append("select count(*) from TdOperationLog ol where 1=1 ");
        if (StringUtils.isNotBlank(moduleName)){
            sb.append(" and ol.moduleName like :moduleName ");
        }
        if (StringUtils.isNotBlank(opTypeName)){
            sb.append(" and ol.opTypeName like :opTypeName ");
        }
        Query query=session.createQuery(sb.toString());
        if (StringUtils.isNotBlank(moduleName)){
            query.setString("moduleName", "%"+moduleName+"%");
        }
        if (StringUtils.isNotBlank(opTypeName)){
            query.setString("opTypeName","%"+opTypeName+"%" );
        }
        return  ((Long)query.uniqueResult()).intValue();  //To change body of implemented methods use File | Settings | File Templates.
    }
}

